package com.ht.module.sys.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ht.module.sys.entity.SysDict;
import com.ht.module.sys.entity.SysDictItem;
import com.ht.module.sys.mapper.SysDictMapper;
import com.ht.module.sys.service.ISysDictItemService;
import com.ht.module.sys.service.ISysDictService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ht.util.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 字典表 服务实现类
 * </p>
 *
 * @author Auto-generator
 * @since 2021-05-19
 */
@Service
public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> implements ISysDictService {
    @Resource
    private SysDictMapper sysDictMapper;


    @Override
    public Pager<SysDict> findPage(Pager<SysDict> pager, SysDict sysDict) {
        QueryWrapper<SysDict> qw=new QueryWrapper<>();
        if(StrUtil.isNotEmpty(sysDict.getDictName())){
            qw.like("dict_name",sysDict.getDictName());
        }
        if(StrUtil.isNotEmpty(sysDict.getDictCode())){
            qw.like("dict_code",sysDict.getDictCode());
        }
        return baseMapper.selectPage(pager,qw);
    }

    @Override
    public List<SysDictItem> getItem(String code) {
        return sysDictMapper.getItem(code).stream().map(x->{
            x.setValue(x.getVal());
            return x;
        }).collect(Collectors.toList());
    }
}
